package com.solution.pc.my.controller.finance;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.solution.admin.finance.wallet.entity.WalletEntity;
import com.solution.admin.finance.wallet.service.WalletFlowService;
import com.solution.admin.finance.wallet.service.WalletService;
import com.solution.common.controller.BaseController;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;

/**
 * PC端个人中心-客户钱包
 * @author lufer
 * @date 2018-05-02 17:18:01
 */
@RequestMapping("/pc/my")
@Controller
public class PcWalletController extends BaseController {

	private Logger logger = LoggerFactory.getLogger(PcWalletController.class);

	@Autowired
	private WalletService walletService;
	@Autowired
	private WalletFlowService walletFlowService;
	
	/**
	 * 跳转我的财富页面
	 * @return string 跳转页面路径
	 * @author lufer
 	 * @date 2018-05-02 17:18:01
	 */
	@RequestMapping("/wallet")
	public String toAddWallet(HttpServletRequest request, Model model) {
		/***************查询某一客户财富汇总****************/
		Map<String, Object> paramMap = new HashMap<String, Object>();
		//从session中获取到当前登录客户ID
		int customerId = (int) getCustomerId();
		//封装查询参数
		paramMap.put("customerId", customerId);
		//查询当前登录客户的财富
		List<WalletEntity> walletList = walletService.listWallet(paramMap);
		if(null != walletList){
			model.addAttribute("walletList",walletList);
		}
		
		/****************查询当前用户的财务流水记录*******************/
		//分页相关(每页显示10条数据）
		PageParam pageParam = super.getPageParam(request,10);
		//查询参数（支出类型）
		String payType = request.getParameter("payType");
		Map<String, Object> flowParamMap = new HashMap<String, Object>();
		//分页查询当前登录用户的财务流水记录
		//封装查询参数
		flowParamMap.put("customerId", customerId);
		flowParamMap.put("payType", payType);
		PageBean pageBean = walletFlowService.listWalletFlowPage(pageParam, flowParamMap);
		List<Object> flowList = pageBean.getRecordList();
		model.addAttribute("flowList",flowList);
		model.addAttribute("pageBean", pageBean);
		//把参数回传到请求页面
		model.addAttribute("payType", payType);
		model.addAttribute("page","wallet");
		return "pc/my/finance/wallet";
	}

}
